<?php
namespace catchAdmin\apidoctor\controller;

use think\Request;
use catcher\CatchResponse;
use catcher\base\CatchRequest;
use catcher\base\CatchController;
use app\common\model\PatientInfo as PatientInfoModel;
use think\exception\ValidateException;
use catchAdmin\apidoctor\validate\PatientValidate;

class Patient extends CatchController
{ 
    /**
     * 患者管理
     * @param CatchRequest $request
     * @return \think\response\Json
     */
    public function get_patient_manage(CatchRequest $request): \think\response\Json
    {
        $req = $request->param();
        $req['doctor_code'] = request()->userInfo['doctor_code'];
        $req['user_id'] = request()->userInfo['id'];
        return CatchResponse::paginate((new PatientInfoModel)->getDoctorPatient($req));
    }

    /**
     * 健康档案
     * @param CatchRequest $request
     * @return \think\response\Json
     */
    public function get_patient_jkda(CatchRequest $request): \think\response\Json
    {
        $req = $request->param();

        #验证参数
        try {
            validate(PatientValidate::class)
                ->scene('get_patient_jkda')
                ->check($req);
        } catch (ValidateException $e) {
            return CatchResponse::fail($e->getError());
        }
        return CatchResponse::success((new PatientInfoModel)->getPatientInfo($req['patient_id'], 3));
    }

    /**
     * 院内医疗
     * @param CatchRequest $request
     * @return \think\response\Json
     */
    public function get_patient_ynyl(CatchRequest $request): \think\response\Json
    {
        $req = $request->param();

        #验证参数
        try {
            validate(PatientValidate::class)
                ->scene('get_patient_ynyl')
                ->check($req);
        } catch (ValidateException $e) {
            return CatchResponse::fail($e->getError());
        }
        return CatchResponse::success((new PatientInfoModel)->getInOutData($req['id']));
    }

    /**
     * 家庭成员
     * @param CatchRequest $request
     * @return \think\response\Json
     */
    public function get_patient_family(CatchRequest $request): \think\response\Json
    {
        $req = $request->param();

        #验证参数
        try {
            validate(PatientValidate::class)
                ->scene('get_patient_family')
                ->check($req);
        } catch (ValidateException $e) {
            return CatchResponse::fail($e->getError());
        }
        return CatchResponse::success((new PatientInfoModel)->getPatientIdRelation($req['patientId']));
    }

    /**
     * 患者顶部信息
     * @param CatchRequest $request
     * @return \think\response\Json
     */
    public function get_hzd_patient_top(CatchRequest $request): \think\response\Json
    {
        $req = $request->param();

        #验证参数
        try {
            validate(PatientValidate::class)
                ->scene('get_hzd_patient_top')
                ->check($req);
        } catch (ValidateException $e) {
            return CatchResponse::fail($e->getError());
        }
        return CatchResponse::success((new PatientInfoModel)->getPatientTop($req['patientId']));
    }
}